<?php

namespace api\controller;

// +----------------------------------------------------------------------
// | 属性数据控制层
// +----------------------------------------------------------------------

use common\controller\VerifyController;
use common\service\ProjectCapacityReportDailyService;
use think\Exception;
use think\Request;
use think\Response;


class ProjectCapacityReportDailyController extends VerifyController
{
    /** @var ProjectCapacityReportDailyService */
    protected $projectCapacityReportDailyService;

    public function _initialize()
    {
        $this->projectCapacityReportDailyService = ProjectCapacityReportDailyService::getInstance();
    }

    /**
     * 时段查询
     * @param Request $request
     * @return Response
     * @throws Exception
     */
    public function selectByStepCategory(Request $request)
    {
        $param = $request->param()['param'];


        $res = $this->projectCapacityReportDailyService->selectByStepCategory($param);
        return json(success_response("", $res));
    }

    /**
     * 单条上报
     * @param Request $request
     * @return Response
     * @throws Exception
     */
    public function saveByStepCategory(Request $request)
    {
        $param = $request->param()['param'];

        try {
            $res = $this->projectCapacityReportDailyService->saveByStepCategory($param);
        } catch (\Throwable $e) {
            throw_strack_exception($e->getMessage(), $e->getCode());
        }
        return json(success_response("", $res));
    }

    /**
     * 批量上报
     * @param Request $request
     * @return Response
     * @throws Exception
     */
    public function saveByCapacityList(Request $request)
    {
        $param = $request->param()['param'];
        try {
            $res = $this->projectCapacityReportDailyService->saveByCapacityList($param);
        } catch (\Throwable $e) {
            throw_strack_exception($e->getMessage(), $e->getCode());
        }

        return json(success_response("", $res));
    }


    /**
     * 查询项目范围产能需求
     * @param Request $request
     * @return Response
     * @throws Exception
     */
    public function getStatisticsByRange(Request $request)
    {
        $param = $request->param()['param'];
        $res = $this->projectCapacityReportDailyService->getStatisticsByRange($param);
        return json(success_response("", $res));
    }


    /**
     * 查询项目月产能需求
     * @param Request $request
     * @return Response
     * @throws Exception
     */
    public function getStatisticsByMonth(Request $request)
    {
        $param = $request->param()['param'];
        $res = $this->projectCapacityReportDailyService->getStatisticsByMonth($param);
        return json(success_response("", $res));
    }
}
